package com.chatroomdemo.controller;

import com.chatroomdemo.model.Friend;
import com.chatroomdemo.service.FriendService;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/friend")
public class FriendController {
    @Autowired
    private FriendService friendService;

    /**
     * @author 陈嘉宇
     * 获取好友列表
     * @param session
     * @param session
     * @return List<Friend> 
     */
    @GetMapping("/getFriendList")
    public List<Friend> getFriendList(HttpSession session){
        if(session==null){
            log.info("session==null");
            return new ArrayList<Friend>();
        }
        Integer userId = (Integer) session.getAttribute("session_userId");
        if(userId==null){
            log.info("不存在session_userId");
            return new ArrayList<Friend>();
        }
        return friendService.getFriendList(userId);
    }
}
